package com.ice.body.business.dao;

import com.ice.body.business.model.ReagentStock;
import com.ice.base.dao.BaseDao;
import com.ice.body.business.vo.ReagentStockVo;
import com.ice.body.dashboard.model.TotalStockVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

/**
 * Created with GuoYanBin.
 * Description:业务接口-试剂库存 mapper
 * Date: 2021-06-22
 * Time: 10:15
 */
@Mapper
public interface ReagentStockDao extends BaseDao<ReagentStock>{


    @Update("update t_reagent_stock set impurity = #{impurity} where batchNo = #{batchNo} " )
    Integer batchUpdateImpurity(ReagentStock model);

    @Select("SELECT cName ,batchNo ,count(*) as count FROM t_reagent_stock where state = 1  group by cName ,batchNo  ")
    ArrayList<ReagentStockVo> selectTotal();

    void insertModel(ReagentStock model);

    ReagentStock getByEpcCode(String epcCode);

    String getStateByEpcCode(String epcCode);

    //增加室内使用记录
    int addUseInRoom(HashMap<String,Object> paramMap);
    //更新剩余数量
    int updateLeftWeighByEpc(HashMap<String,Object> paramMap);

    Integer updateByEpcCode(ReagentStock model);

    Integer checkReagentInWarehouse(ReagentStock model);


    List<ReagentStock> getExpireReagent();

    Integer insertToExpire(ReagentStock model);

    List<ReagentStock> getExpireWarning();

    void deleteExpire(Integer id);

    @Select("select a.cName , count(*) as count, a.deptId from t_reagent_stock a where a.state not in ('8','9') GROUP BY a.cName , a.deptId  having a.deptId = #{deptId}")
    ArrayList<TotalStockVo> getTotalStock(@Param("deptId") Long deptId);

    @Select("select cName , count(*) as count ,MAX(createTime) as createTime from t_reagent_stock   GROUP BY cName  ORDER BY createTime desc limit 20")
    ArrayList<TotalStockVo> getTotalStockLimit();

}